<?php
namespace Partner\Controller;

use Utuo\BackgroundController;

class ConfigController extends BackgroundController{
	
	protected function _initialize(){
		$this->setControllerTitle("合作商高级设置 ");
		$this->setActionTitle(array(
			'index' => '修改设置'
		));
	}
	
	// 修改设置
	public function indexAction(){
		$m = M("PartnerConfig");
		$config = $m->field('copyright,logo,contact')->find($this->aid);
		if(!$config){
			$data = array(
				'id' => $this->aid
			);
			if(!$m->data($data)->add()){
				$this->error("添加合作商信息失败");				
			}
			$config = $m->find($this->aid);
		}
		$this->assign('config', $config);
		$this->display();
	}
	
	// 提交修改设置
	public function indexPostAction(){
		$d = D('PartnerConfig');
		if ($d->create()) {
			$this->id = $this->aid;
			if (false !== $d->save()) {
				$this->ajaxSuccess('修改合作商高级设置成功');
			} else {
				$this->ajaxError('修改合作商高级设置失败');
			}
		} else {
			$this->ajaxError($d->getError());
		}
	}
	
	// 文件上传
	public function uploadAction() {
		$upload = new \Utuo\Upload();
		$info = $upload->uploadOne();
		if (!$info) {
			$this->ajaxError($upload->getError());
		}else{
			$this->ajaxSuccess("上传成功", $info);
		}
	}
}